package com.easyCode.util;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 大忽悠
 * @create 2023/1/19 10:13
 */
public class ReflectionUtils {

    public static List<Field> getAllDeclaredFileds(Class<?> c){
        List<Field> fieldList=new ArrayList<>();
        doGetAllDeclaredFields(c,fieldList);
        return fieldList;
    }

    private static void doGetAllDeclaredFields(Class<?> c, List<Field> fieldList) {
        fieldList.addAll(List.of(c.getDeclaredFields()));
        //如果父类是object,就停止寻找
        if(!c.getSuperclass().equals(Object.class)){
            doGetAllDeclaredFields(c.getSuperclass(),fieldList);
        }
    }
}
